//获取数组第二大的数字
function getSecond(arr) {
    const len = arr.length
    if(len < 2) return null
    let max = arr[0], second = arr[0]
    for(let i = 0; i < len; i++) {
        if(arr[i] > max) {
            second = max
            max = arr[i]
        } else if(arr[i] > second) {
            second = arr[i]
        }
    }
    return second
}

console.log(getSecond([5,1,4,3,6,9,2,7]))